<?php
class ManageController extends AdminController
{
    public function init()
    {
        $this->tableName='ad';
        parent::init();
    }
    public function indexAction()
    {
        $this->list=$this->model->field('id,name,intro,width,height,create_user_id,create_time,update_user_id,update_time,status,key')->getlist();
        $this->display();
    }
    public function addAction()
    {
        if (IS_POST) {
            $zym_7['name']=I('name', 'str', '');
            if (!$zym_7['name']) {
                $this->error('请输入链接名称');
            }
            $zym_7['key']=I('key', 'en', '');
            if (!$zym_7['key']) {
                $this->error('请输入链接地址');
            }
            $zym_7['width']=I('width', 'int', 0);
            $zym_7['height']=I('height', 'int', 0);
            $zym_7['code']=I('code', 'str', '');
            $zym_7['intro']=I('intro', 'str', '');
            $zym_7['status']=I('status', 'int', 1);
            $zym_7['type']=I('type', 'int', 1);
            $zym_7['create_user_id']=$_SESSION['admin']['userid'];
            $zym_7['create_time']=NOW_TIME;
            if ($this->model->add($zym_7)) {
                $this->success('添加成功', U('index'));
            } else {
                $this->error('添加失败');
            }
        }
        $this->display();
    }
    public function editAction()
    {
        $zym_6=I('request.id', 'int', 0);
        $zym_5=$this->model->where(array('id'=>$zym_6))->find();
        if (IS_POST) {
            $zym_7['name']=I('name', 'str', '');
            if (!$zym_7['name']) {
                $this->error('请输入链接名称');
            }
            $zym_7['width']=I('width', 'int', 0);
            $zym_7['height']=I('height', 'int', 0);
            $zym_7['code']=I('code', 'str', '');
            $zym_7['intro']=I('intro', 'str', '');
            $zym_7['status']=I('status', 'int', 1);
            $zym_7['type']=I('type', 'int', 1);
            $zym_7['update_user_id']=$_SESSION['admin']['userid'];
            $zym_7['update_time']=NOW_TIME;
            $zym_7['id']=$zym_6;
            if ($this->model->edit($zym_7)) {
                $this->success('修改成功', U('index'));
            } else {
                $this->error('修改失败');
            }
        }
        $this->info=$zym_5;
        $this->display();
    }
    public function showAction()
    {
        $zym_6=I('request.id', 'int', 0);
        $this->info=$this->model->where(array('id'=>$zym_6))->find();
        $this->display();
    }
}
